import React from 'react'
import { Link } from 'react-router-dom'
import GUtils from '@/utils'

const Config = (Action) => {
  const Handlers = {
    enabled({ id, enabled, name }) {
      enabled = !enabled
      let op = enabled ? '启用' : '禁用'
      GUtils.confirm(op, `确认${op}门店 [${name}] 吗?`, () => {
        Action.enabled(id, enabled)
      })
    },
    buildQRImg(vo) {
      Action.setNewState({ loading: true })
      Action.buildQRImg(vo.id, () => {
        Action.setNewState({ loading: false })
      })
    },
  }
  const columns = [
    {
      title: 'ID',
      dataIndex: 'uid',
      width: 40,
      render: (v) => <Link to={`detail/view?id=${v}`}>{v}</Link>,
    },

    {
      title: '门店信息',
      dataIndex: 'name',
      width: 160,
      render(v, { contact }) {
        return (
          <div>
            <div>名称： {v}</div>
            <div>电话： {contact}</div>
          </div>
        )
      },
    },
    {
      title: '地址信息',
      dataIndex: 'province',
      width: 160,
      render(v, { province, city, district, street }) {
        return (
          <div>
            <div>省份： {province}</div>
            <div>城市： {city}</div>
            <div>
              地址： {district} {street}
            </div>
          </div>
        )
      },
    },
    {
      title: '负责人',
      dataIndex: 'managerName',
      width: 120,
      render(v, { managerPhone }) {
        return (
          <div>
            <div>姓名： {v}</div>
            <div>登录账号： {managerPhone}</div>
          </div>
        )
      },
    },

    {
      title: '停车',
      dataIndex: 'supportParkingDiscount',
      width: 180,
      render(v, vo) {
        return (
          <div>
            <div>停车政策： {vo.parkingPolicy} </div>
            <div>支持停车优惠：{v ? '是' : '否'}</div>
            {v && (
              <div>
                <div>订单时长要求: {vo.parkingOrderDuration}分钟</div>
                <div>免费停车时长: {vo.parkingFreeHour}小时</div>
                <div>
                  停车券领取时间要求: {vo.parkingDiscountApplyDelta}分钟
                </div>
                <div>会员订单时长要求: {vo.parkingVipOrderDuration}分钟</div>
              </div>
            )}
          </div>
        )
      },
    },

    {
      title: '状态',
      dataIndex: 'enabled',
      width: 40,
      render: GUtils.renderEnabledValue,
    },

    {
      title: '操作',
      dataIndex: 'id',
      width: 150,
      render(id, vo) {
        return (
          <div>
            {GUtils.renderDetailLink(id, 'mr-8')}
            {window.isRoot && GUtils.renderEditLink(id, 'mr-8')}
            {window.isRoot &&
              GUtils.renderEnabledLink(vo, '门店', 'name', Action)}

            <a className="ml-8" onClick={Handlers.buildQRImg.bind(this, vo)}>
              生成店铺二维码
            </a>
          </div>
        )
      },
    },
  ]
  return {
    ...window.CONFIG.getPagerConfig(Action),
    columns,
  }
}

export default Config
